//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - lower
//===================================================================================


namespace App.Data.SqlServer.Repositories {
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using App.Model;

    public class JobCategoryRepository : BaseRepository, IJobCategoryRepository {
        public JobCategoryRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork) {
        }
        public void Create(JobCategory jobCategory) {
            this.GetDbSet<JobCategory>().Add(jobCategory);
            this.UnitOfWork.SaveChanges();
        }

        public JobCategory GetJobCategory(Guid jobCategoryId) {
            return this.GetDbSet<JobCategory>()
                .Where(c => c.Id == jobCategoryId)
                .Single();
        }

        public void Update(JobCategory updatedJobCategory) {
            this.GetDbSet<JobCategory>().Attach(updatedJobCategory);
            this.SetEntityState(updatedJobCategory, updatedJobCategory.Id == Guid.Empty
                ? EntityState.Added
                : EntityState.Modified);
            this.UnitOfWork.SaveChanges();
        }

        public void Delete(Guid jobCategoryId) {
            JobCategory JobCategoryToDelete = this.GetJobCategory(jobCategoryId);
            this.GetDbSet<JobCategory>().Remove(JobCategoryToDelete);
            this.UnitOfWork.SaveChanges();
        }

        public IQueryable<JobCategory> Find()
        {
            return this.GetDbSet<JobCategory>();
        }

        public IQueryable<JobCategory> GetAll()
        {
            return this.GetDbSet<JobCategory>();
        }
    }
}
